home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-01-05 | 3.7 KB | 157 lines | [TEXT/PJMM] |
- unit PopMenus2;
-
- interface
-
- uses
- Tools;
-
- type
- PopMenu2 = record
- menuH: MenuHandle; { ID of the menu }
- titleRect, { Rectangle of title }
- menuRect: Rect; { Rectangle of menu }
- last: Integer { last item selected }
- end;
-
- procedure NewPopUp2 (var theMenu: MenuHandle; var thePopMenu: PopMenu2; curItem: Integer; box: Rect);
- function PopSelect2 (var theMenu: PopMenu2): Integer;
- procedure UpdateMenu2 (theMenu: PopMenu2; drawTitle: Boolean);
-
- implementation
-
- {----------------------------------------------}
-
- procedure NewPopUp2 (var theMenu: MenuHandle; var thePopMenu: PopMenu2; curItem: Integer; box: Rect);
-
- { Create the popup and initialize the record. }
-
- var
- oldStyle: Style;
- titleLen, oldSize, oldFont: Integer;
- theInfo: FontInfo;
- curPort: GrafPtr;
- theTitle: str255;
-
- begin
-
- GetPort(curPort);
- oldFont := curPort^.txFont;
- oldSize := curPort^.txSize;
- oldStyle := curPort^.txFace;
- TextFont(0);
- TextSize(0);
- TextFace([]);
- with thePopMenu do
- begin
- menuH := theMenu;
- last := curItem;
- InsertMenu(menuH, -1);
- HLock(Handle(menuH));
- theTitle := menuH^^.menuData;
- titleLen := StringWidth(theTitle) + 3;
- GetFontInfo(theInfo);
- with theInfo, box do
- SetRect(menuRect, left + titleLen, top, left + titleLen + menuH^^.menuWidth, top + ascent + descent + leading);
- if (menuRect.right > box.right) then
- menuRect.right := box.right;
- with box do
- SetRect(titleRect, left - 5, top, left + titleLen, menuRect.bottom);
- HUnlock(Handle(menuH));
- end;
- TextFont(oldFont);
- TextSize(oldSize);
- TextFace(oldStyle);
-
- end; { NewPopUp2 }
-
- {----------------------------------------------}
-
- procedure UpdateMenu2 (theMenu: PopMenu2; drawTitle: Boolean);
-
- var
- theRect: Rect;
- theStr: Str255;
- oldStyle: Style;
- oldSize, oldFont: Integer;
- theInfo: FontInfo;
- curPort: GrafPtr;
- theStyle: Style;
-
- begin
-
- GetPort(curPort);
- oldFont := curPort^.txFont;
- oldSize := curPort^.txSize;
- oldStyle := curPort^.txFace;
- TextFont(0);
- TextSize(0);
- TextFace([]);
- with theMenu do
- begin
- theRect := menuRect;
- OffsetRect(theRect, 2, 2);
- FrameRect(theRect);
- theRect := menuRect;
- EraseRect(theRect);
- theRect := menuRect;
- InsetRect(theRect, -1, -1);
- PenPat(QDGlobals^.black);
- FrameRect(theRect);
- GetItem(menuH, last, theStr);
- MoveTo(menuRect.left + 14, menuRect.top + 12);
- GetItemStyle(menuH, last, theStyle);
- TextFace(theStyle);
- DrawString(Strip2Size(theStr, menuRect.right - menuRect.left - 15));
- if drawTitle then
- begin
- TextFace([]);
- theStr := menuH^^.menuData;
- MoveTo(menuRect.left - StringWidth(theStr) - 3, menuRect.top + 12);
- DrawString(theStr);
- end;
- end;
- TextFont(oldFont);
- TextSize(oldSize);
- TextFace(oldStyle);
-
- end; { UpdateMenu }
-
- {----------------------------------------------}
-
- function PopSelect2 (var theMenu: PopMenu2): Integer;
-
- var
- thePoint: Point;
- result: Longint;
- oldResFile: Integer;
-
- begin
-
- oldResFile := CurResFile;
- PopSelect2 := 0;
- with theMenu do
- begin
- BitClr(Ptr(HiliteMode), pHiliteBit);
- InvertRect(titleRect);
- thePoint := menuRect.topLeft; { topLeft }
- LocalToGlobal(thePoint);
- if menuH <> nil then
- begin
- CheckItem(menuH, last, true);
- result := PopupMenuSelect(menuH, thePoint.V, thePoint.H, last);
- CheckItem(menuH, last, false);
- BitClr(Ptr(HiliteMode), pHiliteBit);
- InvertRect(titleRect);
- if (result <> 0) and (LoWord(result) <> last) then
- begin
- last := LoWord(result);
- PopSelect2 := last;
- UpdateMenu2(theMenu, false);
- end;
- end;
- end;
- UseResFile(oldResFile);
-
- end; { PopSelect2 }
-
- end.